define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'pro/vipuser/index',
                    add_url: 'pro/vipuser/add',
                    edit_url: 'pro/vipuser/edit',
                    del_url: 'pro/vipuser/del',
                    multi_url: 'pro/vipuser/multi',
                    table: 'gzns_user_vip_level',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        // {field: 'user_id', title: __('User_id')},
                        // {field: 'vip_level_id', title: __('Vip_level_id')},
                        // {field: 'level.vip_type', title: __('Level.vip_type'), searchList: {"1":__('Vip_type 1'),"2":__('Vip_type 2')}, formatter: Table.api.formatter.status},
                        // {field: 'level.name', title: __('Level.name')},
                      {field: 'real_name', title: __('Real_name')},
                      {field: 'en_name', title: __('En_name')},
                      {field: 'phone', title: __('Phone')},
                      {field: 'sex', title: __('Sex'), searchList: {"0":__('Sex 0'),"1":__('Sex 1'),"2":__('Sex 2')}, formatter: Table.api.formatter.status},
                      {field: 'native_place', title: __('Native_place')},
                        // {field: 'company_name', title: __('Company_name')},
                        // {field: 'start_time', title: __('Start_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'end_time', title: __('End_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'month_notice', title: __('Month_notice')},
                        // {field: 'week_notice', title: __('Week_notice')},
                        // {field: 'day_notice', title: __('Day_notice')},
                        // {field: 'info.nick_name', title: __('Info.nick_name')},
                        // {field: 'info.avatar', title: __('Info.avatar'), formatter: Table.api.formatter.image},
                        // {field: 'info.real_name', title: __('Info.real_name')},

                        {
                          field: 'operate', title: __('Operate'),
                          table: table,
                          events: Table.api.events.operate,
                          formatter: Table.api.formatter.operate,
                          // buttons: [
                          //   {
                          //     name: '会员申请历史',
                          //     text: __('会员申请历史'),
                          //     title: __('会员申请历史'),
                          //     classname: 'btn btn-xs btn-warning btn-addtabs',
                          //     icon: 'fa fa-list',
                          //     url: 'pro/vipapply/index?type=sub&user_id={user_id}'
                          //   }
                          // ],
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {

            Controller.api.bindevent();
            $('#c-vip_level_id').data("params", function (obj) {
                return {custom: {vip_type: $('#c-vip_type').val()}};
            });

            $('#c-vip_type').on('change',function () {
                $('#c-vip_level_id').selectPageClear();
            })


        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
